| Conditions | 1 |
| Paths | 8 |
| Total Lines | 83 |
| Code Lines | 45 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /*! |
||
| 67 | function () { |
||
| 68 | function Button(element) { |
||
| 69 | this._element = element; |
||
| 70 | } // Getters |
||
| 71 | |||
| 72 | |||
| 73 | var _proto = Button.prototype; |
||
| 74 | |||
| 75 | // Public |
||
| 76 | _proto.toggle = function toggle() { |
||
| 77 | var triggerChangeEvent = true; |
||
| 78 | var addAriaPressed = true; |
||
| 79 | var rootElement = $(this._element).closest(Selector.DATA_TOGGLE)[0]; |
||
| 80 | |||
| 81 | if (rootElement) { |
||
| 82 | var input = this._element.querySelector(Selector.INPUT); |
||
| 83 | |||
| 84 | if (input) { |
||
| 85 | if (input.type === 'radio') { |
||
| 86 | if (input.checked && this._element.classList.contains(ClassName.ACTIVE)) { |
||
| 87 | triggerChangeEvent = false; |
||
| 88 | } else { |
||
| 89 | var activeElement = rootElement.querySelector(Selector.ACTIVE); |
||
| 90 | |||
| 91 | if (activeElement) { |
||
| 92 | $(activeElement).removeClass(ClassName.ACTIVE); |
||
| 93 | } |
||
| 94 | } |
||
| 95 | } |
||
| 96 | |||
| 97 | if (triggerChangeEvent) { |
||
| 98 | if (input.hasAttribute('disabled') || rootElement.hasAttribute('disabled') || input.classList.contains('disabled') || rootElement.classList.contains('disabled')) { |
||
| 99 | return; |
||
| 100 | } |
||
| 101 | |||
| 102 | input.checked = !this._element.classList.contains(ClassName.ACTIVE); |
||
| 103 | $(input).trigger('change'); |
||
| 104 | } |
||
| 105 | |||
| 106 | input.focus(); |
||
| 107 | addAriaPressed = false; |
||
| 108 | } |
||
| 109 | } |
||
| 110 | |||
| 111 | if (addAriaPressed) { |
||
| 112 | this._element.setAttribute('aria-pressed', !this._element.classList.contains(ClassName.ACTIVE)); |
||
| 113 | } |
||
| 114 | |||
| 115 | if (triggerChangeEvent) { |
||
| 116 | $(this._element).toggleClass(ClassName.ACTIVE); |
||
| 117 | } |
||
| 118 | }; |
||
| 119 | |||
| 120 | _proto.dispose = function dispose() { |
||
| 121 | $.removeData(this._element, DATA_KEY); |
||
| 122 | this._element = null; |
||
| 123 | } // Static |
||
| 124 | ; |
||
| 125 | |||
| 126 | Button._jQueryInterface = function _jQueryInterface(config) { |
||
| 127 | return this.each(function () { |
||
| 128 | var data = $(this).data(DATA_KEY); |
||
| 129 | |||
| 130 | if (!data) { |
||
| 131 | data = new Button(this); |
||
| 132 | $(this).data(DATA_KEY, data); |
||
| 133 | } |
||
| 134 | |||
| 135 | if (config === 'toggle') { |
||
| 136 | data[config](); |
||
| 137 | } |
||
| 138 | }); |
||
| 139 | }; |
||
| 140 | |||
| 141 | _createClass(Button, null, [{ |
||
| 142 | key: "VERSION", |
||
| 143 | get: function get() { |
||
| 144 | return VERSION; |
||
| 145 | } |
||
| 146 | }]); |
||
| 147 | |||
| 148 | return Button; |
||
| 149 | }(); |
||
| 150 | /** |
||
| 188 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.